package com.eastcom.collection.tools.alarm

import java.awt.TexturePaintContext.Int;
import java.sql.Date;
import java.sql.Timestamp
import java.sql.Types;
import java.text.SimpleDateFormat
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


import com.eastcom.collection.provider.*
import com.sun.java.util.jar.pack.Instruction.Switch;
import com.sun.org.apache.bcel.internal.generic.NEW;

import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory;
import org.apache.commons.net.ftp.FTPFile
import org.apache.commons.net.ftp.FTPFileFilter
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
/**
 * 任务类，可配置
 * @author yuanyue
 *
 */
class SimpleTxtFileTaskDirector_Alarmer_Lm {
//	/************************配置属性，可以修改，请尽量使用英文防止中文编码问题***************************/
//	final String[] ftpRemotePath =
//	[
//		"/home/dongxin/lm1/log",
//		"/home/dongxin/lm2/log"
//	]
//	final String[] ftpLocalPath =
//	[
//		"/home/ipnet/mystope/data/lm1",
//		"/home/ipnet/mystope/data/lm2"
//	]
//	final String ftpIp = "10.11.244.119"
//	final String ftpUser = "dongxin"
//	final String ftpPasswd = "dx@wlan"
//	final int ftpPort = 21
//	final int ftpFileLimit = 200
//	final String ftpSystem = "UNIX"
//	final String ftpControlEnCode = "UTF-8"
//	final String ftpFileEnCode = "UTF-8"
//	final String ftpServerLanguage = "zh"
//	final String ftpFileNameRegex = "lm_monitor\\.(\\d+)"
//	final long fileLimit = 2000000
//	final String dstdbBean = "oracle_39_nhm"
//	final String timeFormat = "yyyy/MM/dd HH:mm:ss"
//	final String fileNameTimeFormat = "yyyyMMddHHmm"
//	final String[] regex =
//	[
//		"(\\d+/\\d+/\\d+ \\d+:\\d+:\\d+)\\|(\\d+)\\|(\\d+)\\|(\\d+)\\|(\\d+)\\|"
//	]
//	final int[][] groupId =
//	[
//		[1,5]
//	]
//	final int parseLineNumOnce = 1
//	final String objectId = "TEST"
//	final String eventId = "TEST"
//	final String insertSql = "insert into NHM_RADUIS_LM_MONITOR_10MIN(START_TIME,ONLINEUSERCOUNT,IP) values(?,?,?)"
//	/***************************可配置部分结束***********************************************/
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//	static ThreadPoolTaskExecutor threadPoolTaskExecutor
//	static MQCommunication mq
//	static List<String> dstFieldList = new ArrayList()
//	static List<Integer> dstFieldTypeList = new ArrayList()
//	static int[] sqlTypes
//	List<List<String>> parseResultList = new ArrayList()
//	static Log logger = LogFactory.getLog(SimpleTxtFileTaskDirector_Alarmer_Lm.class)
//
//
//	/*********************initJob和doJob是要被程序调用的方法**************************/
//	public boolean initJob(String jobId){
//		doAlarmInit()
//		doDbInit()
//	}
//
//	public boolean doJob(String jobId){
//		doFtp()
//		logger.debug("SimpleTxtFileTaskDirector_Alarmer_Lm doFtp任务完成！")
//		doParseFile()
//		logger.debug("SimpleTxtFileTaskDirector_Alarmer_Lm doParseFile任务完成！")
//		doAlarmerJob()
//		logger.debug("SimpleTxtFileTaskDirector_Alarmer_Lm doAlarmerJob任务完成！")
//	}
//
//
//	/************************下面是自己使用的方法**********************/
//	private boolean doAlarmInit(){
//		try{
//			JmsJndiConfig jmsConfig = new JmsJndiConfig()
//			jmsConfig.initialContextFactory = PropertyPlaceholderConfigurerProvider.getContextProperty("java.naming.factory.initial")
//			jmsConfig.providerUrl = PropertyPlaceholderConfigurerProvider.getContextProperty("java.naming.provider.url")
//			jmsConfig.securityAuthentication = PropertyPlaceholderConfigurerProvider.getContextProperty("java.naming.security.authentication")
//			jmsConfig.securityPrincipal = PropertyPlaceholderConfigurerProvider.getContextProperty("java.naming.security.principal")
//			jmsConfig.securityCredentials = PropertyPlaceholderConfigurerProvider.getContextProperty("java.naming.security.credentials")
//			jmsConfig.referral = PropertyPlaceholderConfigurerProvider.getContextProperty("java.naming.referral")
//
//
//			Map<String, Object> propertyMap = new HashMap()
//			propertyMap.put("jmsJndiConfig", jmsConfig)
//			propertyMap.put("factoryName", PropertyPlaceholderConfigurerProvider.getContextProperty("fm.sconnectionFactory"))
//			propertyMap.put("name", PropertyPlaceholderConfigurerProvider.getContextProperty("fm.squeueName"))
//			DynamicBeanRegisterProvider beanRegister = SpringContextProvider.getBean("beanRegister")
//			beanRegister.addBeanService("mqConnector","com.eastcom.groovy.tools.common.MQCommunication",propertyMap)
//			println SpringContextProvider.getBean("mqConnector")
//			mq = SpringContextProvider.getBean("mqConnector")
//			mq.init()
//		}catch (Exception e) {
//			e.printStackTrace()
//			logger.error(e.getMessage())
//		}
//	}
//
//	private doDbInit(){
//		try{
//			String reg = "\\w+\\s+\\w+([^\\(\\),]+)\\s*\\(([^\\)]+)"
//			String dstTb
//			String dstFields
//			Pattern pattern = Pattern.compile(reg)
//			Matcher matcher = pattern.matcher(insertSql)
//			if(matcher.find()){
//				dstTb = matcher.group(1)
//				dstFields = matcher.group(2)
//			}
//			DbEngine.loadDb(dstdbBean, dstTb, dstFields, dstFieldList, dstFieldTypeList, true)
//			sqlTypes = new int[dstFieldTypeList.size()]
//			for(int i = 0; i < dstFieldTypeList.size(); i++){
//				sqlTypes[i] = dstFieldTypeList.get(i)
//			}
//		}catch(Exception e){
//			e.printStackTrace()
//			logger.error(e.getMessage())
//		}
//	}
//
//
//	public boolean doAlarmerJob(){
//		try{
//			int count = 0
//			List<Integer> flowNoList = new ArrayList()
//			List<Map<String,Object>> alarmerList = new ArrayList()
//			Timestamp time
//			Timestamp maxTime
//			String sql
//			Calendar cl
//			DbEngine dbEngine = SpringContextProvider.getBean("dbEngine")
//			dbEngine.getJdbcUtil().setDataSource(DynamicBeanDomianProvider.getBean(dstdbBean))
//			sql = "select nvl(max(START_TIME),sysdate) TIMESTAMP from NHM_RADUIS_LM_MONITOR_10MIN"
//			List<Map<String,Object>> tempList = dbEngine.getJdbcUtil().queryForList(sql)
//			time = tempList.get(0).get("TIMESTAMP")
//			int[] sqlTypes = new int[2];
//			Object[] params = new Object[2];
//			sqlTypes[0] = Types.TIMESTAMP
//			sqlTypes[1] = Types.TIMESTAMP
//
//			cl = Calendar.getInstance()
//			cl.setTimeInMillis(time.getTime())
//			cl.add(Calendar.MINUTE, -10)
//			params[0] = new Timestamp(cl.getTime().getTime())
//			params[1] = time
//			logger.debug("params[0]="+params[0]+"---"+"params[1]="+params[1])
//			sql = "select * from NHM_RADUIS_LM_MONITOR_10MIN where START_TIME > ? and START_TIME <= ?"
//			List<Map<String,Object>> resultList = dbEngine.getJdbcUtil().queryForList(sql,params,sqlTypes)
//			for(Map<String,Object> map : resultList){
//				BigDecimal onlineUserCount = map.get("ONLINEUSERCOUNT")
//				String ip = map.get("IP")
//				sql = "select tt.agent_id AGENT_ID from rm.rm_device tt where tt.ip_addr='"+ip+"'"
//				Map<String, Object> rs = dbEngine.getJdbcUtil().queryForMap(sql)
//				String deviceAgentId = rs.get("AGENT_ID")
//				if(deviceAgentId == null){
//					continue
//				}
//				if(onlineUserCount > 500000){
//					String msg=""
//					msg ="{da||agent="+deviceAgentId+"||counts=1||messageid=IPNET_YAXIN_CONFIGFILE_LM||message="
//					msg += ip+",唯一性服务器,在线用户数为"+onlineUserCount.toString()+"||keyValue=notcare||kpiname=notcare}"
//					println "发送的告警["+msg+"]"
//					logger.debug("send alamer["+msg+"]")
//					mq.sendMessage(msg)
//				}
//			}
//		}catch(Exception e){
//			e.printStackTrace()
//			logger.error(e.getMessage())
//		}
//
//	}
}